/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Thai Ha Cong
 */
public class Staff implements Serializable {

    private Integer idStaff;
    private String email;
    private String loginName;
    private String password;
    private String firstname;
    private String lastname;
    private String address;
    private Date dob;
    private Date openTime;
    private Date closeTime;
    private List<Issue> issueList;
    private List<Receipt> receiptList;
    private List<Role> roleList;
    private String role;

    public Staff(Integer idStaff, String firstname, String lastname, String role) {
        this.idStaff = idStaff;
        this.firstname = firstname;
        this.lastname = lastname;
        this.role = role;
    }

    public Staff() {
    }

    public Staff(Integer idStaff) {
        this.idStaff = idStaff;
    }

    public Staff(Integer idStaff, String email, String firstname, String lastname, String address, Date dob, String password, String loginName) {
        this.idStaff = idStaff;
        this.email = email;
        this.firstname = firstname;
        this.lastname = lastname;
        this.address = address;
        this.dob = dob;
        this.password = password;
        this.loginName = loginName;
    }

    public Staff(Integer idStaff, String email, String loginName, String password, String firstname, String lastname, String address, Date dob, Date openTime, List<Role> roleList) {
        this.idStaff = idStaff;
        this.email = email;
        this.loginName = loginName;
        this.password = password;
        this.firstname = firstname;
        this.lastname = lastname;
        this.address = address;
        this.dob = dob;
        this.openTime = openTime;
        this.roleList = roleList;
    }

    public Staff(Integer idStaff, String email, String loginName, String password, String firstname, String lastname) {
        this.idStaff = idStaff;
        this.email = email;
        this.loginName = loginName;
        this.password = password;
        this.firstname = firstname;
        this.lastname = lastname;
    }

    public Staff(Integer idStaff,String role, String email, String loginName, String password, String firstname, String lastname, String address, Date dob, Date openTime, Date closeTime) {
        this.idStaff = idStaff;
        this.role = role;
        this.email = email;
        this.loginName = loginName;
        this.password = password;
        this.firstname = firstname;
        this.lastname = lastname;
        this.address = address;
        this.dob = dob;
        this.openTime = openTime;
        this.closeTime = closeTime;
    }

    public Integer getIdStaff() {
        return idStaff;
    }

    public void setIdStaff(Integer idStaff) {
        this.idStaff = idStaff;
    }

    public String getEmail() {
        return email;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "E-mail is required.")},
            emails = {
        @EmailValidator(message = "Invalid E-mail")})
    public void setEmail(String email) {
        this.email = email;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }
    
    public String getPassword() {
        return password;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "Password is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "Password should contains 6-10 characters.", minLength = "6", maxLength = "10")})
    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstname() {
        return firstname;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "FirstName is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "FirstName should contains 2-30 characters.", minLength = "2", maxLength = "30")})
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "LastName is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "LastName should contains 2-30 characters.", minLength = "2", maxLength = "30")})
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getAddress() {
        return address;
    }

    @RequiredStringValidator(message = "Address is required.")
    public void setAddress(String address) {
        this.address = address;
    }

    public Date getDob() {
        return dob;
    }

    @DateRangeFieldValidator(message = "Invalid Date of Birth", min = "01/01/1922", max = "12/31/2012")
    public void setDob(Date dob) {
        this.dob = dob;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    public Date getOpenTime() {
        return openTime;
    }

    public void setOpenTime(Date openTime) {
        this.openTime = openTime;
    }

    public Date getCloseTime() {
        return closeTime;
    }

    public void setCloseTime(Date closeTime) {
        this.closeTime = closeTime;
    }

    public List<Issue> getIssueList() {
        return issueList;
    }

    public void setIssueList(List<Issue> issueList) {
        this.issueList = issueList;
    }

    public List<Receipt> getReceiptList() {
        return receiptList;
    }

    public void setReceiptList(List<Receipt> receiptList) {
        this.receiptList = receiptList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idStaff != null ? idStaff.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Staff)) {
            return false;
        }
        Staff other = (Staff) object;
        if ((this.idStaff == null && other.idStaff != null) || (this.idStaff != null && !this.idStaff.equals(other.idStaff))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Staff{" + "idStaff=" + idStaff + ", email=" + email + ", loginName=" + loginName + ", password=" + password + ", firstname=" + firstname + ", lastname=" + lastname + ", address=" + address + ", dob=" + dob + ", openTime=" + openTime + ", closeTime=" + closeTime + ", issueList=" + issueList + ", receiptList=" + receiptList + ", roleList=" + roleList + '}';
    }

    public String displayInfo() {

        String result = "";

        result = result + "First Name: <b>" + firstname + "</b>"
                + "<br>Last Name: <b>" + lastname + "</b>"
                + "<br>Login Name: <b>" + loginName + "</b>"
                + "<br>Email: <b>" + email + "</b>"
                + "<br>Address: <b>" + address + "</b>"
                + "<br>Your role: <b>" + role + "</b"
                + "<br>"
                + "</br>"
                + "<br><b>You have these rights: </b>";

        for (Role role : roleList) {
            result = result + "<br>- " + role.getName();
        }

        //result = result + "</b>";

        return result;
    }

    public String displayInfo(Staff staff) {

        String result = "";

        result = result + "First Name: <b>" + staff.firstname + "</b>"
                + "<br>Last Name: <b>" + staff.lastname + "</b>"
                + "<br>Login Name: <b>" + staff.loginName + "</b>"
                + "<br>Email: <b>" + staff.email + "</b>"
                + "<br>Address: <b>" + staff.address + "</b>"
                + "<br>"
                + "<br><b>You have these rights: </b>";

        for (Role role : staff.roleList) {
            result = result + "<br>- " + role.getName();
        }

        //result = result + "</b>";

        return result;
    }
}
